package day007;


/**
 * 动态规划之最大子数组问题
 */
public class DynamicPlanning {
    public static void main(String[] args) {
        int[] nums = {-3, 1, 3, -1, 2, -4, 2};

        int cur = 0;
        int max = 0;
        int res = 0;
        for (int i = 0; i < nums.length; i++) {
            cur = nums[i];
            // System.out.println("cur:" + cur);
            max = Math.max(cur, max + cur);
            // System.out.println("max:" + max);
            if (max > res) {
                res = max;
            }
        }
        System.out.println(res);
    }
}
